/*
 *  Copyright 2015 The WebRTC Project Authors. All rights reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

package com.cloudptt.wp.ui.call.group;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.group.fsm.video.GroupCallMemberInfo;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;

/**
 * Fragment for call control.
 */
public class GroupCallSelfLy extends LinearLayout {
	public static String THIS_FILE = "GroupCallSelfLy";
	private Context ctx = null;
	public TextView nameTv;
	public TextView transStateTv;
	public TextView recvStateTv;
	private GroupCallMemberInfo selfInfo = null;

	public GroupCallSelfLy(Context context) {
		this(context, null);
		this.ctx = context;
		// TODO Auto-generated constructor stub
	}

	public GroupCallSelfLy(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
		this.ctx = context;
		// TODO Auto-generated constructor stub
	}

	public GroupCallSelfLy(Context context, AttributeSet attrs, int defStyleAttr) {
		this(context, attrs, defStyleAttr, 0);
		this.ctx = context;
		// TODO Auto-generated constructor stub
	}

	public GroupCallSelfLy(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		this.ctx = context;
		// TODO Auto-generated constructor stub
		LayoutInflater.from(context).inflate(R.layout.layout_group_call_member_self, this);
		this.nameTv = (TextView) findViewById(R.id.nameTv);
		this.transStateTv = (TextView) findViewById(R.id.transStateTv);
		this.recvStateTv = (TextView) findViewById(R.id.recvStateTv);
	}

	public void updateSelfGroupCallMemberInfo(GroupCallMemberInfo info)
	{
		Log.debug(this.getClass(), "updateGroupCallMemberInfo info = " + info);
		this.selfInfo = info;
		if(info != null)
		{
			String str = this.isTransStr(selfInfo.isTrans());
			this.transStateTv.setText(str);

			str = this.isRecvStr(selfInfo.isRecv());
			this.recvStateTv.setText(str);

			String descStr = selfInfo.getGroupMembInfo().getDscp();
			this.nameTv.setText(descStr);
		}
	}

//	public void updateTransState(int state)
//	{
//		Log.debug(this.getClass(), "updateTransState state = " + state);
//		if(CallConst.VideoTransState_NoPermission == state)
//		{
//			String str = this.isTransStr(false);
//			this.transStateTv.setText(str);
//		}
//		else if(CallConst.VideoTransState_Permission == state)
//		{
//			String str = this.isTransStr(true);
//			this.transStateTv.setText(str);
//		}
//	}
//	public void notifyTransUserInfo(GroupCallMemberInfo info)
//	{
//		Log.debug(this.getClass(), "notifyTransUserInfo info = " + info);
//		updateSelfGroupCallMemberInfo(info);
//	}
//	public void updateRecvState(int state)
//	{
//		Log.debug(this.getClass(), "updateRecvState state = " + state);
//		if(CallConst.VideoRecvState_NoPermission == state)
//		{
//			String str = this.isRecvStr(false);
//			this.recvStateTv.setText(str);
//		}
//		else if(CallConst.VideoRecvState_Permission == state)
//		{
//			String str = this.isRecvStr(true);
//			this.recvStateTv.setText(str);
//		}
//	}
//
	private String isTransStr(boolean isTrans)
	{
		Log.debug(this.getClass(),"isConnectStr isTrans =  "+ isTrans);
		if (isTrans) {
			return ctx.getString(R.string.group_call_trans_grand);
		}
		return ctx.getString(R.string.group_call_trans_idle);
	}

	private String isRecvStr(boolean isRecv)
	{
		Log.debug(this.getClass(),"isRecvStr isRecv =  "+ isRecv);
		if (isRecv) {
			return ctx.getString(R.string.group_call_recv_grand);
		}
		return ctx.getString(R.string.group_call_recv_idle);
	}
}
